import 'package:get/get.dart';
import 'package:permission_handler/permission_handler.dart';
// import 'package:scan/scan.dart';

class ScanLogic extends GetxController {
  // late Rx<ScanController> scanController;

  @override
  void onInit() {
    super.onInit();
    // scanController = Rx(ScanController());
  }

  @override
  void onClose() {
    super.onClose();
    // scanController.value.pause();
  }

  /// 动态申请定位权限
  void requestPermission() async {
    /// 申请权限
    // bool hasPermission = await requestCameraPermission();
  }

  /// 申请定位权限
  /// 授予定位权限返回true， 否则返回false
  Future<bool> requestCameraPermission() async {
    ///获取当前的权限
    var status = await Permission.camera.status;
    if (status == PermissionStatus.granted) {
      ///已经授权
      return true;
    } else {
      ///未授权则发起一次申请
      status = await Permission.camera.request();
      if (status == PermissionStatus.granted) {
        return true;
      } else {
        return false;
      }
    }
  }
}
